<!--
 * @Descripttion: 客户订阅消息
 * @Author: xiao li
 * @Date: 2020-07-06 12:17:07
 * @LastEditors: xiao li
 * @LastEditTime: 2021-04-28 14:26:49
-->
<template>
    <div class="lb-sys-notice">
        <top-nav></top-nav>
        <div class="page-main">
          <lb-tips>
            <p>点击【自动同步模板ID】按钮，将会在你的小程序创建一个个人模板，并把模板ID保存下来，已经可以正常使用的将无需重复同步操作</p>
            <p>模板信息的顺序必须与列表中的对应模板信息顺序一致，否则服务通知将可能发送失败，每次点击【自动同步模板ID】按钮后，需点击表格左下方的保存按钮</p>
          </lb-tips>

          <el-collapse v-model="activeNames">
            <el-collapse-item title="* 【点击查看】如何配置订阅消息模板?" name='1'>
              <div style="height:15px"></div>
              <el-steps direction="vertical" :active="3">
                <el-step title="第一种：点击【自动同步模板ID】，添加模板成功">
                  <div class="notice-description" slot="description">
                    <p></p>
                    <p>成功返回模板ID后，点击<span>【保存】按钮</span>即可</p>
                    <p></p>
                  </div>
                </el-step>
                <el-step title="第二种：点击【自动同步模板ID】，添加模板失败">
                  <div class="notice-description" slot="description">
                    <p></p>
                    <p>1、登录微信公众平台<span>【https://mp.weixin.qq.com】</span>，选择<span>【功能 - 订阅消息】</span></p>
                    <img src="../../../assets/system/notice1.jpg"/>
                    <p></p>
                    <p>2、点击<span>【公共模板库 - 搜索栏】</span>在搜索栏输入模板标题，点击搜索然后手动添加对应的数据。</p>
                    <p>若是没有相关模板，则可以通过<span>【申请模板】</span>来生成所需要的模板信息。</p>
                    <img src="../../../assets/system/notice2.jpg"/>
                    <p></p>
                    <p>3、如下图中红框所示，详细内容应与表格中<span>对应【详细内容】的内容及顺序一致</span>；</p>
                    <img src="../../../assets/system/notice3.jpg"/>
                    <p>4、添加成功后，返回<span>【我的模板】</span>，找到对应模板配置，然后将<span>【模板ID】</span>复制到表格对应<span>【模板ID】</span>栏，最后点击<span>【保存】</span>按钮即可；</p>
                  </div>
                </el-step>
              </el-steps>
            </el-collapse-item>
          </el-collapse>

        <div style="height:20px"></div>
             <el-table
            v-loading="loading"
            :data="tableData"
          :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
            style="width: 100%">
            <el-table-column
              prop="id"
              width="100px"
              label="ID">
            </el-table-column>
            <el-table-column
              prop="sceneDesc"
              width="150px"
              show-overflow-tooltip
              label="模板标题">
            </el-table-column>
            <el-table-column
              prop="example"
              width=""
              label="详细内容">
            </el-table-column>
            <el-table-column
              prop="tmpl_id"
              label="模板ID">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.tmpl_id" placeholder="请输入模板ID"></el-input>
                </template>
            </el-table-column>
            <el-table-column
              prop="address"
              width="160px"
              label="操作">
                <template slot-scope="scope">
                  <div class="table-operate">
                    <lb-button size='mini' plain type='primary' @click="getTmpID(scope.row.id)">自动同步模板ID</lb-button>
                  </div>
                </template>
            </el-table-column>
          </el-table>
          <lb-button type='primary' @click="submitFormInfo()">{{$t('action.save')}}</lb-button>
        </div>
    </div>
</template>

<script>
export default {
  data () {
    return {
      loading: false,
      tableData: [],
      activeNames: []
    }
  },
  activated () {
    this.getFormInfo()
  },
  methods: {
    async getFormInfo () {
      this.loading = true
      let {code, data} = await this.$api.tmpLists()
      this.loading = false
      if (code !== 200) return
      this.tableData = data
    },
    async getTmpID (id) {
      let {code, data} = await this.$api.getTmplId({id})
      if (code !== 200) return
      let queryForm = JSON.parse(JSON.stringify(this.tableData))
      this.$message.success(this.$t('tips.successSub'))
      queryForm.map(item => {
        if (item.id === id) {
          item.tmpl_id = data
          this.tableData = queryForm
        }
      })
    },
    async submitFormInfo () {
      let queryForm = JSON.parse(JSON.stringify(this.tableData))
      let {code} = await this.$api.tmplUpdate(queryForm)
      if (code !== 200) return
      this.$message.success(this.$t('tips.successSave'))
      this.getFormInfo()
    }
  }
}
</script>

<style lang="scss" scoped>
    .lb-sys-notice {
        width: 100%;
        .baseform {
          .el-input {
            width: 300px;
          }
        }
    }
    .notice-description {
      p {
        font-size:14px;
        color:#333;
        padding-bottom:10px;
        span {
          color:#409EFF
        }
      }
      img {
        width:80%;
        height:auto
      }
    }
</style>
